package com.jerry.security.qq.config;

import com.jerry.security.SocialConfigProperties;
import com.jerry.security.qq.QQProperties;
import com.jerry.security.qq.connect.QQConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;

/**
 * 当系统中配置了com.jerry.security.social.qq.app-id这个值时，内部的配置才会生效
 */
@Configuration
@ConditionalOnProperty(prefix = "com.jerry.security.social.qq", name = "app-id")
public class QQAutoConfig extends SocialAutoConfigurerAdapter {

	@Autowired
	private SocialConfigProperties socialConfigProperties;

	@Override
	protected ConnectionFactory<?> createConnectionFactory() {
		QQProperties qqProperties = socialConfigProperties.getQq();
		return new QQConnectionFactory(qqProperties.getProviderId(), qqProperties.getAppId(), qqProperties.getAppSecret());
	}

}
